﻿using Microsoft.AspNetCore.Mvc;
using RobosimAPI.Class;

namespace RobosimAPI.Controllers
{
	[Route("back/Api2/Client/enterEvent")]
	public class EnterEventController : ControllerBase
	{
		[HttpPost]
		public IActionResult EnterEvent([FromBody] EnterEventModel model)
		{
			Account account = new Account(model.user_id);
			Round round = new Round(model.round_id);
			Group group = new Group(round.GroupId);
			Event @event = new Event(group.event_id);
			int[] join = account.GetAllJoinedEvents();
			if (Array.IndexOf(join, group.id) == -1)
			{
				return Ok(new ErrorResponse() { status = -1, errmsg = "Has not apply" });
			}
			Score score = new Score(@event.db_name, account.user_id, round.Id);
			if (score.user_id <= 0)
			{
				return Ok(new ErrorResponse() { status = -2, errmsg = "_USER_NO_SUBMIT_SCORE_" });
			}
			score.is_entered = 1;
			score.Update();
			return Ok(new ErrorResponse() { status = 1, errmsg = "_OK_" });
		}
		public class EnterEventModel
		{
			public int user_id { get; set; }
			public int round_id { get; set; }
		}
	}
}
